package core;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class NativeMethods {
	public static void ShowDialog(String str)
	{
		JPanel panel = null;
		JOptionPane.showMessageDialog(panel, str, 
			    "Error", JOptionPane.ERROR_MESSAGE);
	}
	
	public static ByteArrayOutputStream ToBOS(File file) throws FileNotFoundException
	{
		FileInputStream  fis = new FileInputStream(file);
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
        return bos;
	}
	
	/**
     * Convert the byte array to an int.
     *
     * @param b The byte array
     * @return The integer
     */    
    public static final int byteArrayToInt(byte [] b) {
        return (b[0] << 24)
                + ((b[1] & 0xFF) << 16)
                + ((b[2] & 0xFF) << 8)
                + (b[3] & 0xFF);
    }
    
    public static final byte[] intToByteArray(int value) {
        return new byte[] {
                (byte)(value >>> 24),
                (byte)(value >>> 16),
                (byte)(value >>> 8),
                (byte)value};
    }
    /**
     * Convert the byte array to an int starting from the given offset.
     *
     * @param b The byte array
     * @param offset The array offset
     * @return The integer
     */
    public static int byteArrayToInt(byte[] b, int offset) {
        int value = 0;
        for (int i = 0; i < 4; i++) {
            int shift = (4 - 1 - i) * 8;
            value += (b[i + offset] & 0x000000FF) << shift;
        }
        return value;
    }
}
